Ext.Loader.setConfig({enabled:true});

Ext.application({
    name:'Rms',
    launch:function () {
        Ext.create('Ext.container.Viewport', {
            renderTo: document.body,
            layout : {
                type : 'vbox',
                align : 'center',
                pack : 'center'
            },
            items:[
                {
                    xtype:'form',
                    title:'Login',
                    frame:true,
                    bodyPadding:10,
                    width:350,
                    defaultType:'textfield',
                    defaults:{
                        anchor:'100%'
                    },
                    items:[
                        {
                            allowBlank:false,
                            fieldLabel:'User ID',
                            itemId:'txtUsername',
                            name:'j_username',
                            stateful:true,
                            stateId:'username',

                            emptyText:'User name'
                        },
                        {
                            allowBlank:false,
                            fieldLabel:'Password',
                            itemId:'txtPassword',
                            name:'j_password',
                            emptyText:'Password',
                            inputType:'password'
                        },
                        {
                            xtype:'checkbox',
                            fieldLabel:'Remember me',
                            inputValue:true,
                            name:'remember'
                        }
                    ],

                    buttons:[
                        {
                            text:'Clean',
                            itemId:'btnClean',
                            handler: function(){
                                this.up('form').getForm().reset();
                            }
                        },
                        {
                            text:'Login',
                            itemId:'btnLogin',
                            disabled:true,
                            formBind:true,
                            handler: function(){
                                form = this.up('form').getForm();
                                form.submit({
                                    method : 'POST',
                                    url : 'j_spring_security_check',
                                    success : function(form, action) {
                                        window.location.hash = "index.html";
                                    },
                                    failure : function(form, action) {
                                        console.log("failure");
                                    }
                                })
                            }
                        }
                    ]
                }
            ],
            listeners:{
                afterrender: function(){
                    this.down('#txtUsername').focus(true, 10);
                }
            }
        })
    }
})
